package ro.k.tags;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import ro.k.web.beans.KBeanUtils;
import ro.k.web.beans.order.ManoperaBaseBean;

public class ComandaManopera implements Serializable{
	
	private static final long serialVersionUID = 1629587360726105601L;
	private List<ManoperaBaseBean> manComanda = new ArrayList<ManoperaBaseBean>();
	
	
	public List<ManoperaBaseBean> getManComanda() {
		return manComanda;
	}
	
	public void addManopera(String code){
		if (code != null) {
			DBManopera dbm = new DBManopera();
			ManoperaBaseBean mbb = dbm.getManoperaByCode(code);
			mbb.setCant(1.0);
			mbb.setTotal(Double.parseDouble(mbb.getValoare()));
			manComanda.add(mbb);
		}
	}
	
	public void updateManoperaComanda(String code, Double cant) {
		for (ManoperaBaseBean mb : manComanda) {
			if (mb.getCod().equals(code)) {
				mb.setCant(cant);
				mb.setTotal(Double.parseDouble(mb.getValoare()) * cant);
			}
		}
	}
	
	public void removeMan(Object obj) {
		if (KBeanUtils.isEmpty(obj)) {
			return;
		}
		String code = obj.toString();
		int size = manComanda.size();
		for (int i = 0; i < size; i++) {
			if (manComanda.get(i).getCod().equals(code)) {
				manComanda.remove(manComanda.get(i));
				size--;
				i--;
			}
		}
		for (ManoperaBaseBean mb : manComanda) {
			if (mb.getCod().equals(code)) {
				manComanda.remove(mb);
			}
		}
	}
	
	public double getManComanaTotal() {
		double d = 0;
		for (ManoperaBaseBean mb : manComanda) {
			d += mb.getTotal();
		}
		return d;
	}

	public void addManopera(ManoperaBaseBean mbb) {
		manComanda.add(mbb);
	}
}
